package com.bl.student.dao.redis.auth;

import com.bl.student.dao.redis.AbstractDao;
import com.google.common.base.Optional;
import com.google.common.base.Strings;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Component;

/**
 * Created by yujingyi on 2017/7/26.
 */
@Component
@Log4j2
public class HxAuthDao extends AbstractDao {

    private final String HX_ACCESS_TOKEN_KEY = "HX_ACCESS_TOKEN";

    public void setAccessToken(String accessToken, long expire) {

        set(HX_ACCESS_TOKEN_KEY, accessToken, expire * 1000);

    }

    public Optional<String> getAccessToken() {

        String accessToken = get(HX_ACCESS_TOKEN_KEY);

        return Strings.isNullOrEmpty(accessToken) ? Optional.<String>absent() : Optional.fromNullable(accessToken);
    }


}
